home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / network / ka9q / ka9q_src.arc / MISC.C < prev    next >
C/C++ Source or Header  |  1988-07-28  |  666b  |  39 lines

  1. /* Miscellaneous machine independent utilities */
  2.  
  3. #include "global.h"
  4.  
  5. /* Convert hex-ascii to integer */
  6. int
  7. htoi(s)
  8. char *s;
  9. {
  10.     int i = 0;
  11.     char c;
  12.  
  13.     while((c = *s++) != '\0'){
  14.         if(c == 'x')
  15.             continue;    /* allow 0x notation */
  16.         if('0' <= c && c <= '9')
  17.             i = (i * 16) + (c - '0');
  18.         else if('a' <= c && c <= 'f')
  19.             i = (i * 16) + (c - 'a' + 10);
  20.         else if('A' <= c && c <= 'F')
  21.             i = (i * 16) + (c - 'A' + 10);
  22.         else
  23.             break;
  24.     }
  25.     return i;
  26. }
  27. /* replace terminating end of line marker(s) with null */
  28. rip(s)
  29. register char *s;
  30. {
  31.     register char *cp;
  32.  
  33.     if((cp = index(s,'\r')) != NULLCHAR)
  34.         *cp = '\0';
  35.     if((cp = index(s,'\n')) != NULLCHAR)
  36.         *cp = '\0';
  37. }
  38.  
  39.